// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {
    totalCartCount:0,
    //serverURL:"http://47.109.142.219/api" //服务器地址
    serverURL:"http://8.137.58.133/api"
  },
  _charStr : 'abacdefghjklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789',
  RandomIndex(min, max, i){
    let index = Math.floor(Math.random()*(max-min+1)+min),
        numStart = this._charStr.length - 10;
    //如果字符串第一位是数字，则递归重新获取
    if(i==0&&index>=numStart){
        index = this.RandomIndex(min, max, i);
    }
    //返回最终索引值
    return index;
  },
  getRandomString(len) {
    let min = 0,
        max = this._charStr.length - 1,
        _str = '';
    //判断是否指定长度，否则默认长度为15
    len = len || 15;
    //循环生成字符串
    for (var i = 0, index; i < len; i++) {
        index = this.RandomIndex(min, max, i);
        _str += this._charStr[index];
    }
    return _str;
  },
  getNowDate(){
    let Now = new Date()
    let y = Now.getFullYear()
    let mon = Now.getMonth()+1
    let d = Now.getDate()
    let h = Now.getHours()
    let m = Now.getMinutes()
    let s = Now.getSeconds()
    return ""+y+"-"+mon+"-"+d+" "+h+":"+m+":"+s
  }
})
